#include <iostream>
#include "fstream"
#include "string"

using namespace std;

int main() {
    // 创建流对象
    ofstream ofs;

    ofs.open("test.txt", ios_base::out);

    ofs << "姓" << endl;
    ofs << "名" << endl;

    ofs.close();

    // 读取
    ifstream ifs;
    ifs.open("test.txt", ios::in);
    if (!ifs.is_open()) {

    }

    // 读数据
    // 第一种
    /*char buf[1024] = {0};
    while (ifs >> buf) {
        cout << buf << endl;
    }*/

    // 第二种
    /*char buf1[1024] = {0};
    while (ifs.getline(buf1, sizeof buf1)) {
        cout << buf1 << endl;
    }*/

    // 第三种
    /*string buf2;
    while (getline(ifs, buf2)) {
        cout << buf2 << endl;
    }*/

    // 第四种
    char c;
    while ((c = ifs.get()) != EOF) { // EOF end of file
        cout << c;
    }

    ifs.close();
}

